home *** CD-ROM | disk | FTP | other *** search
-
- //========================================================================
- // The following example routines have been provided by the Technical
- // Support staff at Borland International. They are provided as a
- // courtesy and not as part of a Borland product, and as such, are
- // provided without the assurance of technical support or any specific
- // guarantees.
- //========================================================================
- //
- // TVeXIT:
- // This program is an example of controling the dos screen upon exit.
- // Use of "#pragma exit <function name>" allows our function to be
- // destroyed after the screen has been destructed. Notice the priority
- // number of 31. Since constructors and destructors have priority of
- // 32, 31 causes the destructor( for exit_func ) to be called after
- // the screen destructor.
- //
- //========================================================================
- #define Uses_TApplication
- #define Uses_TStaticText
- #define Uses_TEventQueue
- #define Uses_TEvent
- #define Uses_TKeys
- #define Uses_TRect
- #define Uses_TMenuBar
- #define Uses_TSubMenu
- #define Uses_TMenuItem
- #define Uses_TStatusLine
- #define Uses_TStatusItem
- #define Uses_TStatusDef
- #define Uses_TDeskTop
- #define Uses_TView
- #define Uses_TWindow
- #define Uses_TMenu
- #define Uses_TDialog
- #define Uses_TButton
-
- #include <string.h> //for strcmp()
- #include <stdlib.h>
- #include <tv.h>
-
- const int cmAbout = 100;
-
- int exit_flag = 1; // use this to keep track of exit.
-
- class TMyApp : public TApplication
- {
-
- public:
- TMyApp();
- static TMenuBar *initMenuBar( TRect );
- static TStatusLine *initStatusLine( TRect );
- void handleEvent(TEvent& event);
- void AboutDialog(void);
-
- };
-
-
- TMyApp::TMyApp() :
- TProgInit( &initStatusLine,
- &initMenuBar,
- &initDeskTop
- )
- {
- }
-
-
- void TMyApp::AboutDialog(void)
- {
- char Text[] = "\003TvExit\n\n\n\n"
- "\003Shows you how to control the\n"
- "\003screen upon exit.";
-
-
- TDialog *pd = new TDialog( TRect( 20,2,60,18), "About");
- if( validView(pd) )
- {
- pd->insert( new TStaticText( TRect( 5, 2, 35, 12), Text));
- deskTop->execView(pd);
- }
-
- destroy(pd);
-
- }
-
-
-
- void TMyApp::handleEvent(TEvent& event)
- {
- TApplication::handleEvent( event );
-
- if( event.what == evCommand )
- {
- switch( event.message.command)
- {
- case cmAbout:
- AboutDialog();
- break;
-
- default:
- break;
- }
- clearEvent( event );
- }
- }
-
-
- TStatusLine *TMyApp::initStatusLine(TRect r)
- {
- r.a.y = r.b.y - 1;
-
- return new TStatusLine( r,
- *new TStatusDef( 0, 0xFFFF) +
- *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit) +
- *new TStatusItem( "~Alt-A~ About", kbAltA, cmAbout)
- );
-
- }
-
-
- TMenuBar *TMyApp::initMenuBar( TRect r )
- {
- r.b.y = r.a.y + 1;
- TMenuBar *t;
-
- TMenuItem *two =
- new TMenuItem("~E~xit", cmQuit, kbAltX);
-
- TMenuItem *one =
- new TMenuItem("~\xF0~", kbAltSpace,
- new TMenu( *new TMenuItem("~A~bout", cmAbout, kbAltA)),
- hcNoContext, two);
-
- return ( new TMenuBar( r, new TMenu( *one ) ) );
-
-
- }
-
-
-
- //-------------------------------------------------------------------
- // This is the function which is called upon exit if exit_flag is
- // still equal to 1. Exit_flag is set to zero in main if the user
- // inputs the appropriate command line parameter,i.e., "hello."
- //-------------------------------------------------------------------
- void exitfunc(void)
- {
- if( exit_flag )
- {
- cout << "Syntax: tvexit hello\n" << endl;
- cout << "\nPlease enter ""hello"" after the program name." << endl;
- }
-
- }
-
-
- //----------------------------------------------------------------------
- // #pragma :
- // Use priority 31 because the priority of constructors and destructors
- // (currently) is 32, thus, my function is constructed before and
- // destructed after the TScreen object.
- //----------------------------------------------------------------------
-
- #pragma exit exitfunc 31
-
-
- int main(int argc, char *argv[])
- {
-
- if( strcmp(argv[1], "hello") )
- return -1;
-
- TMyApp myApp;
- myApp.run();
- exit_flag = 0; // turn exit flag off
- return 0;
-
- }
-